package com.cxl.dao;

import com.cxl.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CourseDao {
    @Select("select * from user where username = #{username} and password = #{password}")
    User findByUser(User user);

    @Update("update user set enddate = now() where uid = #{uid}")
    void upenddate(@Param("uid") Integer uid);

    List<Course> findByCourseList();

    @Update("update course set `check` = #{check} where cid = #{cid} ")
    void upCheck(Course course);

    Course findByCourseID(@Param("cid") Integer cid);

    @Update("update course set state = #{state} where cid = #{cid} ")
    void upState(Course course);

    @Select("select * from course_type")
    List<CourseType> findByTypes();

    @Select("select count(*) from course where cname = #{cname}")
    Integer findByCname(@Param("cname") String cname);

    void add(Course course);

    @Update("update course set video = #{video} where cid =#{cid}")
    void addVideo(Course course);

    @Select("select count(*) from middle where uid=#{uid} and cid = #{cid}")
    Integer findByApply(@Param("cid") Integer cid,@Param("uid") Integer uid);

    @Select("select count(*) from remark where cid  = #{cid} and score >= 8")
    Integer findByComment(@Param("cid")Integer cid);

    @Select("select count(*) from remark where cid  = #{cid} and score >= 5 and score < 8")
    Integer findByComment1(@Param("cid")Integer cid);

    @Select("select count(*) from remark where cid  = #{cid} and score  < 5")
    Integer findByComment2(@Param("cid")Integer cid);

    @Select("select r.*,u.username 'uname' from remark  r left join user u on u.uid=r.uid where cid  = #{cid} and score >= 8")
    List<Remark> findByRemark(@Param("cid")Integer cid);

    @Select("select r.*,u.username 'uname' from remark  r left join user u on u.uid=r.uid where cid  = #{cid} and score >= 5 and score < 8")
    List<Remark> findByRemark1(@Param("cid")Integer cid);

    @Select("select r.*,u.username 'uname' from remark  r left join user u on u.uid=r.uid where cid  = #{cid} and  score < 5")
    List<Remark> findByRemark2(@Param("cid")Integer cid);

    void addCom(Remark remark);
}
